import 'dart:io';
import 'dart:isolate';

import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import './ui/login.dart';
import './ui/meeting.dart';
import './ui/member_list.dart';
import './ui/test/test_api.dart';
import './models/meeting_model.dart';

part 'main_ext.dart';

void main() {
  // FlutterForegroundTask.initCommunicationPort();
  runApp(MyApp());
}

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {

  @override
  void initState() {
    super.initState();

    if (Platform.isMacOS || Platform.isWindows) {
      return;
    }

    WidgetsBinding.instance.addPostFrameCallback((_) {
      // Request permissions and initialize the service.
      ServiceManager()._requestPermissions();
      ServiceManager()._initService();
    });
  }

  @override
  Widget build(BuildContext context) {
    return ChangeNotifierProvider(
      create: (context) => MeetingModel(),
      child: MaterialApp(
        routes: {
          "/": (context) => LoginPage(),
          "/login": (context) => LoginPage(),
          "/meeting": (context) => MeetingPage(),
          "/memberList": (context) => MemberListPage(),
          "/test": (context) => TestPage(),
        },
      ),
    );
  }
}
